import request from "@/utils/request";

export const login = (data) => {
  return request({
    method: "POST",
    url: "/api/private/v1/login",
    data,
  });
};

// 获取用户信息
export const updateListApi = (params) => {
  return request({
    method: "GET",
    url: "api/private/v1/users",
    params,
  });
};

export const createListApi = (data) => {
  return request({
    method: "POST",
    url: "/api/private/v1/users",
    data,
  });
};

//  修改 /api/private/v1/users/
export const editListApi = (data) => {
  return request({
    method: "PUT",
    url: "/api/private/v1/users/",
    data,
  });
};

//  删除 /api/private/v1/users/  只需传id
export const delListApi = (id) => {
  return request({
    method: "DELETE",
    url: "/api/private/v1/users/",
    data: {
      id,
    },
  });
};

// 获取某个具体的用户信息
export const getUserInfoApi = (id) => {
  return request({
    method: "GET",
    url: "/api/private/v1/users/",
    params: {
      id,
    },
  });
};

// 这个用法失败
export const changeStateApi = (data) => {
  return request({
    method: "PUT",
    url: "/api/private/v1/users/",
    data,
  });
};

//分配用户权限
export const allocationApi = (id, rid) => {
  return request({
    method: "PUT",
    url: `/api/private/v1/users/${id}/role`,
    data: {
      rid,
    },
  });
};

export const getUserRoleApi = () => {
  return request({
    method: "GET",
    url: "/api/private/v1/roles",
  });
};

// http://vue-shop-api-t.itheima.net/api/private/v1
// 获取权限列表 扁平
export const getUserList = () => {
  return request({
    method: "GET",
    url: "/api/private/v1/rights/list",
  });
};

// 获取商品列表
export const getGoodListApi = (params) => {
  return request({
    method: "GET",
    url: "/api/private/v1/goods",
    params,
  });
};

//删除商品
export const delGoodApi = (id) => {
  return request({
    method: "DELETE",
    url: `api/private/v1/goods/${id}`,
  });
};

//删除具体用户
export const delUserApi = (id) => {
  return request({
    method: "DELETE",
    url: `api/private/v1/roles/${id}`,
  });
};

export const getOrderListApi = (params) => {
  return request({
    method: "GET",
    url: `/api/private/v1/orders`,
    params,
  });
};

// 删除用户权限
export const delRoleApi = (id, rid) => {
  return request({
    method: "DELETE",
    url: `api/private/v1/roles/${id}/rights/${rid}`,
  });
};

//获取树形结构列表
export const getRoleTreeApi = () => {
  return request({
    method: "GET",
    url: "api/private/v1/rights/tree",
  });
};

//角色授权
export const AssignAuthorityApi = (id, data) => {
  return request({
    method: "POST",
    url: `api/private/v1/roles/${id}/rights`,
    data,
  });
};

// 添加角色
export const addUserRoleApi = (data) => {
  return request({
    method: "POST",
    url: "/api/private/v1/roles",
    data,
  });
};
//编辑  修改用户
export const editRoleApi = (id, data) => {
  return request({
    method: "PUT",
    url: `api/private/v1/roles/${id}`,
    data,
  });
};

//获取商品分类列表
export const getClassificationApi = (params) => {
  return request({
    method: "GET",
    url: "api/private/v1/categories",
    params,
  });
};

//删除分类
export const delGoodClassificationApi = (id) => {
  return request({
    method: "DELETE",
    url: `api/private/v1/categories/${id}`,
  });
};
//编辑提交分类
export const editCategoriesApi = (id, data) => {
  return request({
    method: "PUT",
    url: `api/private/v1/categories/${id}`,
    data,
  });
};

//添加提交分类
export const addCategoriesApi = (data) => {
  return request({
    method: "POST",
    url: "api/private/v1/categories",
    data,
  });
};

// categories/:id/attributes
export const getCategoriesApi = (id, params) => {
  return request({
    method: "GET",
    url: `api/private/v1/categories/${id}/attributes`,
    params,
  });
};

//categories/:id/attributes/:attrId
export const editParamsApi = (id, cid, data) => {
  return request({
    method: "PUT",
    url: `api/private/v1/categories/${id}/attributes/${cid}`,
    data,
  });
};
//categories/:id/attributes
export const addParamsApi = (id, data) => {
  return request({
    method: "POST",
    url: `api/private/v1/categories/${id}/attributes/`,
    data,
  });
};

// 删除 categories/:id/attributes/:attrid
export const delParamsApi = (id, cid) => {
  return request({
    method: "DELETE",
    url: `api/private/v1/categories/${id}/attributes/${cid}`,
  });
};

//获取商品信息  https://lianghj.top:8888/api/private/v1/orders/59
export const getOrderInfoApi = (id) => {
  return request({
    method: "GET",
    url: `api/private/v1/orders/${id}`,
  });
};

export const editOrderInfoApi = (id, data) => {
  return request({
    method: "PUT",
    url: `api/private/v1/orders/${id}`,
    data,
  });
};

export const getGoodsCategoriesApi = () => {
  return request({
    method: "GET",
    url: "api/private/v1/categories",
  });
};

//获取分类参数
export const getCategoriesAttributesApi = (id, params) => {
  return request({
    method: "GET",
    url: `api/private/v1/categories/${id}/attributes`,
    params,
  });
};

//添加商品
export const addGoodsApi = (data) => {
  return request({
    method: "POST",
    url: "api/private/v1/goods",
    data,
  });
};
